package com.cn.wanxi.servlet.pageDataFindAll;

import com.alibaba.fastjson.JSONObject;
import com.cn.wanxi.model.MessageModel;
import com.cn.wanxi.service.IMessageService;
import com.cn.wanxi.service.impl.MessageServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

@WebServlet("/messageAdd")
public class messageAllAddServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");

        String name= req.getParameter("name");
        String phone= req.getParameter("phone");
        String mailbox= req.getParameter("mailbox");
        String project= req.getParameter("project");
        String message= req.getParameter("message");

        Date d = new Date();
        //SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String data=sdf.format(d);
//        System.out.println("当前时间：" + sdf.format(d));


        MessageModel messageModel =new MessageModel();
        messageModel.setName(name);
        messageModel.setPhone(phone);
        messageModel.setMailbox(mailbox);
        messageModel.setProject(project);
        messageModel.setMessage(message);
        messageModel.setDate(data);


        IMessageService iMessageService=new MessageServiceImpl();
        int count=iMessageService.messageAdd(messageModel);

        JSONObject jsonObject=new JSONObject();
        jsonObject.put("count",count);
        resp.getWriter().println(jsonObject);
    }
}
